using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using TMS.Application.Common.Interface;
using TMS.Application.RequestDto;
using TMS.Application.ResponseDto;
using TMS.Application.Utils;
using TMS.Domain.Entity;

namespace TMS.Api.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class TokenController: ControllerBase
    {
        private readonly IRepository<StuUsers> _Users;
        
        private readonly IIdentityService _IdentityService;
        private readonly IFileUploadService _fileUploadService;
        public TokenController( IIdentityService IdentityService, IRepository<StuUsers> Users, IFileUploadService fileUploadService)
        {
            
            _IdentityService = IdentityService;
            _fileUploadService = fileUploadService;
            _Users = Users;
        }

        // [AllowAnonymous]
        [HttpPost("/token")]
        public async Task<string> ValidateUser(UserForAuthDto userForAuth)
        {
            var token = await _IdentityService.ValidateUserAsync(userForAuth);

            return token.SerializeObject();//JsonHelp的方法
        }
        // [AllowAnonymous]
        [HttpPost("/refresh")]

        public async Task<string> RefreshToken(AppTokenDto appToken)
        {
            var token = await _IdentityService.RefreshTokenAsync(appToken);

            return token.SerializeObject();//JsonHelp的方法
        }

        // [Authorize]
        [HttpGet("/token")]

        public dynamic get()
        {


            return new
            {
                code = 200,
                msg = "token存在未过期",
                data = ""
            }; //JsonHelp的方法
        }
    }
}